#include <sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdio.h>

int main(void){
    char buff[1024];
    int fd1,fd2;
    int ret;

    fd1=open("./src.txt",O_RDONLY);
    if(-1==fd1){
        return fd1;
    }
    fd2=open("./dest.txt",O_WRONLY|O_CREAT|O_EXCL,0666);
    if(-1==fd2){
        ret=fd2;
        goto out1;
    }
    ret=read(fd1,buff,sizeof(buff));
    if(-1==ret){
        goto out2;
    }
    ret=write(fd2,buff,sizeof(buff));
    if(-1==ret){
        goto out2;
    }
out2:
    close(fd2);
out1:
    close(fd1);
    return ret;

}